//
//  LottieCircleView.swift
//  ShouChong
//
//  Created by yw on 2024/7/30.
//

import Foundation
import SwiftUI
import Lottie

struct LottieCircleView:UIViewRepresentable {
    @Binding var speed:CGFloat
    func makeUIView(context: Context) -> UIView {
        let view = UIView(frame: .zero)
        let lottieView = LottieAnimationView(name: "Animation - 1724912692519")
        lottieView.animationSpeed = 0.2
        lottieView.loopMode = .loop
        lottieView.contentMode = .scaleAspectFit
        lottieView.play()
        view.addSubview(lottieView)
        lottieView.translatesAutoresizingMaskIntoConstraints = false
        lottieView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
        lottieView.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
        lottieView.heightAnchor.constraint(equalToConstant: 300).isActive = true
        lottieView.widthAnchor.constraint(equalToConstant: 300).isActive = true
        
        return view
        
    }
    
    func updateUIView(_ uiView: UIViewType, context: Context) {
        let subView = uiView.subviews.first
        if let lottieView  = subView as? LottieAnimationView {
            lottieView.animationSpeed = speed
        }
    }
    
}
